namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System.Xml.Serialization;
    using SimpleWebServices;
    using Xunit;

    public sealed class SubscriptFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<Subscript>()
                .DerivesFrom<InnerElements>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .Implements<IXmlSerializable>()
                .XmlRoot("sub")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            Subscript expected = new Subscript
            {
                Id = "id",
                Class = "class",
                Language = "fr",
                Title = "title",
                Elements =
                {
                    new TextString("Some text")
                }
            };

            string xml = "<sub id='id' class='class' lang='fr' title='title'>Some text</sub>";
            Subscript actual = xml.Deserialize<Subscript>();

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }

        [Fact]
        public void deserializeEmpty()
        {
            Assert.NotNull("<sub />".Deserialize<Subscript>());
        }

        [Fact]
        public void serialize()
        {
            Subscript obj = new Subscript
            {
                Id = "id",
                Class = "class",
                Language = "fr",
                Title = "title",
                Elements =
                {
                    new TextString("Some text")
                }
            };

            string xpath = "1=count(/sub[@id='id'][@class='class'][@lang='fr'][@title='title'][text()='Some text'])";

            Assert.True((bool)obj.Serialize().CreateNavigator().Evaluate(xpath));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new Subscript());
        }

        [Fact]
        public void op_Deserialize_string_string_string()
        {
            Subscript expected = new Subscript
            {
                Id = "id",
                Class = "class",
                Language = "fr",
                Title = "title",
                Elements =
                {
                    new TextString("Some text")
                }
            };

            string xml = "<sub id='id' class='class' lang='fr' title='title'>Some text</sub>";
            Subscript actual = new Subscript().Deserialize("sub", null, xml) as Subscript;

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }
    }
}